Lamp = cc.Node.extend({
	ctor:function(p){
		this._super();
		p.addChild(this, 7, TAG_LAMP);
		this.loadLamp();
	},
	loadLamp : function(){
		this.setCascadeOpacityEnabled(true);
		var lamp = new Button(this, 10, TAG_LAMP, "#lamp/lp1.png",this.callback);
		lamp.setCascadeOpacityEnabled(true);
		var lid = new Button(this, 10, TAG_LAMP_LID, "#lamp/lp2.png",this.callback);
		lid.setPosition(0, 25);
	},
	loadFire : /**
				 * 点火
				 */
	function(){
		var fire = new cc.Sprite("#fire/1.png");
		fire.setPosition(25, 75);
		this.getChildByTag(TAG_LAMP).addChild(fire, 20, TAG_LAMP_FIRE);

		var animFrames = [];
		for (var i = 1; i < 4; i++) {
			var str = "fire/huo" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.03);
		var action = cc.animate(animation);
		var repeat = cc.repeatForever(action);
		fire.runAction(repeat);
	},
	putLamp:/**
			 * 放入酒精灯
			 */
	function(){
		// world 650,190
		var move = cc.moveTo(0.5, cc.p(-150, 0));
		var seq = cc.sequence(move, this.getParent().callNext);
		this.getChildByTag(TAG_LAMP).runAction(seq);
		// 等待2-3min，
		this.getParent().clock.loadTip("#tool/tip1.png");
		this.getParent().clock.doTime(3, 0.5);
	},
	putLampResult:function(){
		this.getChildByTag(TAG_LAMP).setPosition(-150, 0);
	},
	removeLamp:/**
				 * 拿出酒精灯
				 */
	function(){
		var move = cc.moveTo(0.5,cc.p(0, 0));
		var func = cc.callFunc(function(){
			gg.flow.next();
			// 展示蒸发皿中的晶体
			this.getParent().getChildByTag(TAG_POT_NODE).showNaCl();
		}, this);
		var seq = cc.sequence(move, func);
		this.getChildByTag(TAG_LAMP).runAction(seq);
	},
	outFire:function(){
		var fire = this.getChildByTag(TAG_LAMP).getChildByTag(TAG_LAMP_FIRE);
		var seq = cc.sequence(cc.fadeOut(0.3),cc.delayTime(1.8),cc.callFunc(function(){
			gg.flow.next();
			this.getParent().lampNode.runAction(cc.fadeOut(0.5));
			var seq = cc.sequence(cc.fadeOut(0.5), cc.callFunc(function(){
				this.removeFromParent(true);
			}, this));
			this.runAction(seq);
			// 冷却至室温
			this.getParent().clock.loadTip("#tool/tip2.png");
			this.getParent().clock.doTime(3, 0.5);	
		}, this));
		fire.runAction(seq);
	},
	openLid:function(p){
		var ber = cc.bezierTo(1, [cc.p(50, 100),cc.p(50, 30),cc.p(50, -15)]);
		var seq = cc.sequence(ber, this.getParent().callNext);
		p.runAction(seq);
	},
	openLidResult:function(){
		this.getChildByTag(TAG_LAMP_LID).setPosition(50, -15);
	},
	closeLid:function(p){
		var ber = cc.bezierTo(1, [cc.p(50, -15),cc.p(60, 100),cc.p(0, 25)]);
		var delay = cc.delayTime(0.3);
		var move = cc.moveTo(0.5, cc.p(0, 75));
		var move2 = cc.moveTo(0.5, cc.p(0, 25));
		var seq = cc.sequence(ber, delay, move, move2);
		p.runAction(seq);
		this.scheduleOnce(function(){
			this.outFire();
		},0.5);
	},
	callback:function(p){
		switch(p.getTag()){
			case TAG_LAMP:
				if(gg.flow.flow.action == ACTION_DO1){
					this.putLamp();
				} else if(gg.flow.flow.action == ACTION_DO2){
					this.removeLamp();
				}
				break;
			case TAG_LAMP_LID:
				if(gg.flow.flow.action == ACTION_DO1){
					this.openLid(p);
				} else if(gg.flow.flow.action == ACTION_DO2){
					this.closeLid(p);
				}
				break;
		}
	}
});
